package com.yndsoft.jc.ui.categorypage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yndsoft.jc.R;
import com.yndsoft.jc.model.ProductType;

import java.util.List;

/**
 * Created by hasee on 2017/12/4.
 */

public class GridAdapter extends BaseAdapter {

    private List<ProductType> list;
    private Context context;
    private LayoutInflater inflater;

    public GridAdapter(List<ProductType> list, Context context) {
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {

        GridViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_category_gridview, null);
            holder = new GridViewHolder();
            holder.title_grid = convertView.findViewById(R.id.title_grid);
            convertView.setTag(holder);
        } else {
            holder = (GridViewHolder) convertView.getTag();
        }

        holder.title_grid.setText(list.get(position).getName());

        return convertView;
    }

    class GridViewHolder {
        private TextView title_grid;
    }
}
